var id= $.cookie("MYID");
var urlfrom=window.location.href;
var typeid = $.cookie("newstypeid");
//var typeid =43;             //写死 要从上一页传入
var typename=$.cookie("newstypename");
/*
*
*/
var currentIndex=1; //起始页数
var pageSize=10;//一页显示几条新闻
//var newsnum=0;//第几条新闻
var readyover=0;//控制页面滚动 1可以滚动加载 0不可以
var isclick=0;//控制按钮点击状态 0当前没有正在点击的按钮 1有点击的按钮
var p1=0;
var current=0;
var keywordcount=0;//屏蔽关键词个数
var urlcount=0;//屏蔽网址个数
var newscount=0;//屏蔽新闻个数
var newstitle={};//用新闻ID 获取新闻标题
var allavawidth=parseInt(window.screen.width)*0.5;
var avawidth=parseInt(parseInt(window.screen.width)/5);//手指滑动距离
var urltypearr=[];//请求新闻的ID
var urltypearrindex=0;//初始页面
var nowpage="";//当前的滚动页
var screenh=parseFloat(window.screen.availHeight);
console.log(screenh);
var screenstyleh=screenh-171;
console.log(screenstyleh);
$(".PinnedTopicFeed .photo_wrapper .photo a").append("<img class='topic_photo_img' src='hyimg/"+typeid+".png'>");
$(".PinnedTopicFeed .info_wrapper .info").append("<span class='TopicNameSpan TopicName'>"+typename+"</span>");

//cookie失效 页面返回
if(!$.cookie("zhzx")){
    if(IsPC()){
        location.href="zonghenews.html";
    }
    else{
        location.href="home.html"
    }
};
if(/from=zonghe/.test(urlfrom)){
    $(".HeaderSwitcherItem:nth-child(2)").attr("class","HeaderSwitcherItem is_active");
    urltypearr=$.cookie("zhzx").split(",");
    document.title = "Pulu-资讯圈-综合资讯";
    for(var i=0;i<urltypearr.length;++i){
        if(typeid==urltypearr[i].match(/[0-9]+/)[0]){
            urltypearrindex=i;
        }
    }
}
else if(/from=hangye/.test(urlfrom)){
    $(".HeaderSwitcherItem:nth-child(3)").attr("class","HeaderSwitcherItem is_active");
    urltypearr=$.cookie("hyxw").split(",");
    document.title = "Pulu-资讯圈-行业新闻";
    for(var i=0;i<urltypearr.length;++i){
        if(typeid==urltypearr[i].match(/[0-9]+/)[0]){
            urltypearrindex=i;
        }
    }
}
else if(/from=xingqu/.test(urlfrom)){
    $(".HeaderSwitcherItem:last-child").attr("class","HeaderSwitcherItem is_active");
    urltypearr=$.cookie("xqah").split(",");
    document.title = "Pulu-资讯圈-兴趣爱好";
    for(var i=0;i<urltypearr.length;++i){
        if(typeid==urltypearr[i].match(/[0-9]+/)[0]){
            urltypearrindex=parseInt(i);
        }
    }
};
//插入滚动区域
var currenthash={};//保存每个类别的页码
var allcode="";
for(var i=0;i<urltypearr.length;i++){
    if(!currenthash[alltypeid]){
        currenthash[alltypeid]=1;//默认页码1
    }
    if(typeid==urltypearr[i].match(/[0-9]+/)[0]){
        urltypearrindex=i;
        nowpage="#typeid"+typeid;//加载页面
    }
    var alltypeid=urltypearr[i].match(/[0-9]+/)[0];
    allcode+="<div class='SimpleToggle Toggle HomeMainFeed swiper-slide' id='typeid"+alltypeid+"' style='height:"+screenstyleh+"px;'><div class='bodybox'></div><div class='pleasewait' id='pleasewait"+alltypeid+"'><div class='waitbox'> <div class='waiting'>加载中...</div><div class='nonews' style='display:none'>没有更多信息</div></div> </div></div>"
};
$("#page_wrapper .swiper-wrapper").append(allcode);

//创建滑动
var haveajax=[];
var mySwipermain;
var stopswiper="";
console.log(urltypearrindex);
function addnewswiper(){

    mySwipermain = new Swiper ('#page_wrapper',{
        paginationClickable: true,
        touchRatio : 1,
        initialSlide :urltypearrindex,
        loop : true,
        //切换页面
        onTransitionEnd: function(swiper){
            //alert("yemianqiehuanle");

            if(!$.cookie("totop")){
                var nowindex;
                if(swiper.activeIndex==0){
                    nowindex=swiper.activeIndex;
                }else{
                    nowindex=swiper.activeIndex-1;
                }
                console.log(swiper.activeIndex);
                console.log(nowindex);
                //选择城市
                choicecity="";
                //修改页面地址
                nowpage="#typeid"+urltypearr[nowindex].match(/[0-9]+/)[0];
                //修改新闻类型typeid
                typeid=urltypearr[nowindex].match(/[0-9]+/)[0];
                console.log(typeid);
                //展示页index
                urltypearrindex=nowindex;
                //分类修改
                typename=urltypearr[nowindex].match(/[\u4e00-\u9fa5|a-zA-Z]+/)[0];
                $(".PinnedTopicFeed .photo_wrapper .photo a img").attr("src","hyimg/"+typeid+".png");
                $(".PinnedTopicFeed .info_wrapper .info span.TopicName.TopicNameSpan:last-child").html(typename);
                //城市
                showcityname();
                //页面返回没有加载区域
                if(!document.querySelector("#typeid"+typeid+" .bodybox")){
                    console.log("补全");
                    $("#typeid"+typeid).prepend("<div class='bodybox'></div>");
                }
                if(!$("#typeid"+typeid+" .newsbox").length>0){
                    //console.log("没有加载内容");
                    console.log("调用执行4");
                    //swiper-no-swiping
                    $("body").css("overflow","hidden");
                    aj(nowpage,currenthash[typeid],pageSize);
                }
            }
            else{
                current=parseFloat($.cookie("currentIndex"));
                currenthash[typeid]=current;
                currentIndex=current;//更改以后加载的页码
                var allpagenum=parseFloat($.cookie("currentIndex"))*parseFloat(pageSize);//一共有多少条新闻
                console.log("完成有历史");
                aj2(nowpage,1,allpagenum);
                alert("返回数据："+$.cookie("totop"));
            }

        }
    });
}
addnewswiper();
//mySwipermain.disableTouchControl();
var haveloadcity=false;//已经下载了城市列表
//城市选择部分
function showcityname(){
    if(typeid==7){
        $("#choicecity").css("display","block");//选择城市按钮
        if(!haveloadcity){
            $("#citylist").load("newscitylist.html");//加载城市列表
            haveloadcity=true;
        }
        choicecity=$.cookie("choicecity7");
        if($.cookie("choicecityname7")){
            $("#choicecity").html($.cookie("choicecityname7"));//页面展示城市名
        }
    }
    else if(typeid==36){
        $("#choicecity").css("display","block");//选择城市按钮
        if(!haveloadcity){
            $("#citylist").load("newscitylist.html");//加载城市列表
            haveloadcity=true;
        }
        choicecity=$.cookie("choicecity36");
        if($.cookie("choicecityname36")){
            $("#choicecity").html($.cookie("choicecityname36"));//页面展示城市名
        }
    }
    else if(typeid==110){
        $("#choicecity").css("display","block");//选择城市按钮
        if(!haveloadcity){
            $("#citylist").load("newscitylist.html");//加载城市列表
            haveloadcity=true;
        }
        choicecity=$.cookie("choicecity110");
        if($.cookie("choicecityname110")){
            $("#choicecity").html($.cookie("choicecityname110"));//页面展示城市名
        }
    }
    else{
        $("#choicecity").css("display","none");//选择城市按钮
    }
}
showcityname();

$("#maingobackbtn").click(function(){
    history.go(-1);
});
//时间 几天前 几分钟前
function getDateTimeStamp(dateStr){
    dateStr=dateStr.replace(/T/g,' ');
    dateStr=dateStr.replace(/\.[0-9]+/g,'');
    return Date.parse(dateStr.replace(/-/gi,"/"));
}
function getDateDiff(dateTimeStamp){
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = now - dateTimeStamp;
    if(diffValue < 0){return;}
    var monthC =diffValue/month;
    var weekC =diffValue/(7*day);
    var dayC =diffValue/day;
    var hourC =diffValue/hour;
    var minC =diffValue/minute;
    if(monthC>=1){
        result="" + parseInt(monthC) + "月前";
    }
    else if(weekC>=1){
        result="" + parseInt(weekC) + "周前";
    }
    else if(dayC>=1){
        result=""+ parseInt(dayC) +"天前";
    }
    else if(hourC>=1){
        result=""+ parseInt(hourC) +"小时前";
    }
    else if(minC>=1){
        result=""+ parseInt(minC) +"分钟前";
    }else
        result="刚刚";
    return result;
}
/*
*页面刷新 重新加载
*/
$(".TopicNameSpan.TopicName").click(function(){
    //$(".HomeMainFeed div").remove();
    $("#typeid"+typeid+" .newsbox").remove();
    currenthash[typeid]=1;
    currentIndex=1;
    $("#waiting").css("display","block");
    $("#nonews").css("display","none");
    console.log("调用执行3");
    aj(nowpage,currentIndex,pageSize);
});
/*
//iframe点击
*/
function addEvent(o, evt, func) {
    if (o.addEventListener) o.addEventListener(evt, func, false);
    else if (o.attachEvent) o.attachEvent('on' + evt, func);
}
function addDocClickEvt(e) {
    addEvent(e.contentWindow.document,"click", function(e){
        hrefto(e.target);
    });
}
/*
//iframe处理图片
*/
function showImg( url,imgid,title,nurl) {
    //showImg(data.Data[i].thumb,data.Data[i].id,)
    //var imgid = Math.random(),
    frameid = 'frameimg' + imgid;
    window['iframeimg'+imgid] = '<img id="iframeimg"'+imgid+'  data-title="'+title+'" data-pagenum="'+currentIndex+'" data-newsimg="'+url+'" data-id="'+imgid+'" data-url="'+nurl+'" src=\''+url+'\' style="width:100%;opacity:0;"/>';
    //var newimg='<iframe id="'+frameid+'" src="javascript:parent[\'iframeimg'+imgid+'\'];" frameBorder="0" scrolling="no" width="100%"></iframe>';
    var newimg='<iframe id="'+frameid+'" onload="addDocClickEvt(this)" src="javascript:parent[\'iframeimg'+imgid+'\'];" style="background:url('+url+') no-repeat;background-size:100%;z-index:-1;" frameBorder="0" scrolling="no" width="100%"></iframe>';
    return newimg;
}
/*
 //选择城市
 */
var choicecity="";
$("#choicecity").click(function(){
    $("#citybox").css("display","block");
    $("#page_wrapper").css("display","none");
});
function changecity(e){
    $("#choicecity").html(e.innerHTML);
    $("#citybox").css("display","none");
    $("#page_wrapper").css("display","block");
    //添加网址拼接参数
    if(e.dataset.num){
        var choicenum=e.dataset.num;
        choicecity="&city="+e.dataset.num;
        if(typeid==7){
            $.cookie("choicecity7",choicecity);
            $.cookie("choicecityname7",e.innerHTML);//选择的城市名 跳转返回使用
        }else if(typeid==36){
            $.cookie("choicecity36",choicecity);
            $.cookie("choicecityname36",e.innerHTML);//选择的城市名 跳转返回使用
        }else if(typeid==110){
            $.cookie("choicecity110",choicecity);
            $.cookie("choicecityname110",e.innerHTML);//选择的城市名 跳转返回使用
        }
        $("#hotcity div p").attr("class","");
        $("#hotcity div p").each(function(){
            console.log($(this)[0].dataset.num);
            console.log(choicenum);
            if($(this)[0].dataset.num===(choicenum)){
                $(this).attr("class","choiced");
            }
        });
    }else{  //选择的是全国
        choicecity="";
        $.cookie("choicecity7","");
        $.cookie("choicecity36","");
        $.cookie("choicecity110","");
        $.cookie("choicecityname7","全国");
        $.cookie("choicecityname36","全国");
        $.cookie("choicecityname110","全国");
        $("#hotcity div p").attr("class","");
    }
    var cityid=e.dataset.num;//城市ID
    var cityname=e.innerHTML;//城市名称
    //从头加载数据
    currenthash[typeid]=1;
    currentIndex=1;
    pageSize=10;
    //清除原数据
    $("#typeid"+typeid+" .newsbox").remove();
    $("#waiting").css("display","block");
    $("#nonews").css("display","none");
    console.log("调用执行2");
    aj(nowpage,currentIndex,pageSize);

    var choicep=document.querySelectorAll("#historylist p");
    //console.log(choicep);
    var len=choicep.length;
    var canappend="yes";//能否直接插入
    for(var i= 0;i<len;i++){
        if(choicep[i].dataset.num===cityid){
            canappend="no";
        }
    }
    //能插入新历史
    if(canappend==="yes"){
        //历史是否有6个 第一个要替换掉
        if(len>=6){
            console.log("数量达到限制");
            console.log($("#historylist>p:nth-child(2)"));
            $("#historylist>p:nth-child(2)").remove();
        }
        $(("#historylist")).append("<p onclick='changecity(this)' data-num='"+cityid+"'>"+cityname+"</p>");
    }

    //搜索页面和主页切换
    $("#page").css("display","block");
    $("#searchcitypage").css("display","none");
    //搜索清空
    $("#searchcitypage div").remove();
    //搜索框清空
    $('#searchcityinput').val("");
    //搜索按钮取消按钮 还原（隐藏）
    //搜索按钮隐藏
    $("#searchcity").css("display","none");
    $("#cancelsearchcity").css("display","none");
    //搜索框圆角还原
    $(".search .searchdiv").css("border-radius","5px");

}
//城市右侧导航条转
function citynav(e){
    var t = $("#"+e.dataset.id).offset().top-100;
    $(window).scrollTop(t);//滚动到锚点位置
}
/*
//城市搜索
*/
    //焦点事件
$("#searchcityinput").focus(function(){
    $("#page").css("display","none");
    //取消按钮显示
    $("#cancelsearchcity").css("display","block");
    //搜索页面显示
    $("#searchcitypage").css("display","block");
});
    //监听输入框
$('#searchcityinput').bind('input propertychange', function() {
    if($('#searchcityinput').val()){
        //搜索按钮显示
        $("#searchcity").css("display","block");
        //搜索框圆角修改
        $(".search .searchdiv").css("border-radius","5px 0 0 5px");
    }else{
        //搜索按钮隐藏
        $("#searchcity").css("display","none");
        //搜索框圆角还原
        $(".search .searchdiv").css("border-radius","5px");
    }
});
    //取消搜索 关闭搜索页面
$("#cancelsearchcity").click(function(){
    //搜索按钮隐藏
    $("#searchcity").css("display","none");
    //搜索框圆角还原
    $(".search .searchdiv").css("border-radius","5px");
    //清空输入框
    $('#searchcityinput').val("");
    //页面切换
    $("#page").css("display","block");
    $("#searchcitypage").css("display","none");
    //取消按钮隐藏
    $("#cancelsearchcity").css("display","none");
    //搜索清空
    $("#searchcitypage div").remove();
})
    //点击搜索按钮进行搜索
$("#searchcity").click(function(){
    var val=$('#searchcityinput').val();
    //进行搜索
    var py=pinyin.getFullChars(val).toLowerCase();
    $("#searchcitypage div").remove();
    if(py){
        var reg=new RegExp(py);
        var alllist=$("#citylist div");//所有的城市列表
        var alllen=alllist.length;//所有列表个数
        console.log(alllen);
        for(var i=0;i<alllen;i++){
            if(reg.test(alllist[i].className)){
                console.log(alllist[i]);
                $("#searchcitypage").append($(alllist[i]).clone());
            }else{

            }
        }
    }
});

//关闭城市页面 展示主页面
$("#citybox .header span").click(function(){
    $("#citybox").css("display","none");
    $("#page_wrapper").css("display","block");
});

$(window).load(function(){
    if($.cookie("newsid")&&/\d/.test($.cookie("newsid"))){ //定位操作
        document.getElementsByClassName("HomeMainFeed")[0].removeChild(document.getElementsByClassName("HomeMainFeed")[0].firstChild);
        //$(".newsbox").remove();
        //$("#typeid"+typeid+" .newsbox").remove();
        current=parseFloat($.cookie("currentIndex"));
        currenthash[typeid]=current;
        currentIndex=current;//更改以后加载的页码
        var allpagenum=parseFloat($.cookie("currentIndex"))*parseFloat(pageSize);//一共有多少条新闻
        console.log("完成有历史");
        aj2(nowpage,1,allpagenum);
        //var toheight=parseFloat($.cookie("scrollTop"));
        //var thisid=$.cookie("newsid");
        //var t=parseFloat($.cookie("totop"));
        //$(window).scrollTop(t);
        //$(".HomeMainFeed").scrollTop(t);
        //document.body.scrollTop=t;
        readyover=1;
        //currentIndex=current;
    }
    else{
        readyover=1;
        console.log("去调用执行4");
        //aj(nowpage,currentIndex,pageSize);
        //第一次进来 在swiper中加载
    }
});
//$(window).scroll(function(){
//$("#typeid"+typeid).scroll(function(){
$(".swiper-slide").scroll(function(){
    var mainheight=$("#typeid"+typeid).height();
    var windowheight=$("#typeid"+typeid+" .bodybox").height();
    var chajuli=mainheight-$("#typeid"+typeid+" .bodybox").offset().top+250;
    var topscroll=$("#typeid"+typeid+" .bodybox").offset().top;
    //导航条隐藏显示
    ////if(chajuli<-88){
    //if(topscroll<88){
    //    $(".fixed_header").css({"position":"fixed","top":"-88px"});
    //    console.log(window.screen.height);
    //    console.log(screenh-88);
    //    $(".SimpleToggle.Toggle.HomeMainFeed.swiper-slide").css({"height":screenstyleh+88+"px"});
    //    $(".wrapper.home_feed.swiper-wrapper").css("padding-top","88px");
    //}else{
    //    $(".fixed_header").css({"position":"absolute","top":"0px"});
    //    $(".wrapper.home_feed.swiper-wrapper").css("padding-top","172px")
    //    $(".SimpleToggle.Toggle.HomeMainFeed.swiper-slide").css("height",screenstyleh+"px");
    //}
    var cz=windowheight-mainheight+5;
    //不是选择城市的 滚动效果
    if($("#citybox").css("display")==="none"){
        //if(readyover===1&&chajuli<cz){
        if(readyover===1&&chajuli>windowheight){
            console.log("====================");
            console.log("加载："+chajuli+":"+windowheight);
            console.log("====================");
            readyover=0;
            //console.log("第几页的新闻？："+currentIndex);
            //调整加载中
            currenthash[typeid]=parseInt(currenthash[typeid])+1;
            currentIndex=currenthash[typeid];
            aj(nowpage,currentIndex,pageSize);
        }else{
            console.log("不够:"+chajuli+":"+windowheight);
        }
    }
});
var ajrunning="no";
function aj(nowpage,currentIndex,pageSize){
    if(!currentIndex){
        currentIndex=1;
    }
    ajrunning="yes";
    isclick=0;
    onlyexternal=true;//jinzhihuadong
    //关闭滑动
    $.ajax({
        type:"get",
        datatype:"json",
        url:"https://www.pulu.com/webapi/api/PuluNews/GetPageDataByTypeId1?typeId="+typeid+"&currentIndex="+currentIndex+"&pageSize="+pageSize+"&userId="+id+choicecity,
        success:function(data){
            //还原加载区域
            $("#pleasewait").css("padding","0");
            if(data.Data==""||!data.Data){
                $("#pleasewait"+typeid+" .waiting").css("display","none");
                $("#pleasewait"+typeid+" .nonews").css("display","block");
            }
            else{
                if(data.Data.length<10){
                    $("#pleasewait"+typeid+" .waiting").css("display","none");
                    $("#pleasewait"+typeid+" .nonews").css("display","block");
                }
                var num=0;
                //所有要添加的字符串
                var allhtmlword="";
                for(var i=0;i<data.Data.length;i++){
                    //console.log("isclick",isclick);
                    num++;
                    //截取时间
                    var tim="";
                    if(data.Data[i].published_date){
                        tim=getDateDiff(getDateTimeStamp(data.Data[i].published_date));
                    };
                    //用新闻的ID 获取新闻的标题
                    if(newstitle[data.Data[i].id]){
                        //已经保存了新闻标题
                    }else{
                        //保存新闻标题
                        newstitle[data.Data[i].id]=data.Data[i].title;
                    }
                    if(data.Data[i].thumb){
                        var iframeimg=showImg(data.Data[i].thumb,data.Data[i].id,data.Data[i].title,data.Data[i].url);
                        allhtmlword+="<div class='newsbox'  id='"+data.Data[i].id+"'><div class='tpl-2' onclick='hrefto(this)' data-title='"+data.Data[i].title+"'data-pagenum='"+currentIndex+"' data-newsimg='"+data.Data[i].thumb+"' data-id='"+data.Data[i].id+"' data-url='"+data.Data[i].url+"'><a><div class='clr'><div class='info-content rt'><div class='text-content' ><h2><p>"+data.Data[i].title+"</p></h2></div><div class='news-from'><span class='src-net'>"+data.Data[i].sitename+"·"+tim+"</span><span class='sendit rt' onclick='shareit(this)' data-nid='"+data.Data[i].id+"'><img src='../img/newsshare2.png' data-nid='"+data.Data[i].id+"'></span><span class='src-delet rt overflow' onclick='deleteitfun(this)' data-url='"+data.Data[i].host+","+data.Data[i].sitename+"' id='new"+data.Data[i].id+"'><img src='../img/newsdel2.png'></span></div></div><div class='pic-content'>"+iframeimg+"</div></div></a></div></div>";
                    }else if(!data.Data[i].thumb){
                        allhtmlword+="<div class='newsbox'  id='"+data.Data[i].id+"'><div class='tpl-3' data-id='"+data.Data[i].id+"' onclick='hrefto(this)' data-title='"+data.Data[i].title+"' data-url='"+data.Data[i].url+"' data-pagenum='"+currentIndex+"'><a><div class='text-content'><h2><p>"+data.Data[i].title+"</p></h2></div><div class='news-from'><span class='src-net'>"+data.Data[i].sitename+"·"+tim+"</span><span class='sendit rt' onclick='shareit(this)' data-nid='"+data.Data[i].id+"'><img src='../img/newsshare2.png' data-nid='"+data.Data[i].id+"'></span><span class='src-delet rt overflow' id='new"+data.Data[i].id+"' onclick='deleteitfun(this)' data-url='"+data.Data[i].host+","+data.Data[i].sitename+"'><img src='../img/newsdel2.png'></span></div></a></div></div>";
                    }
                    if(num===data.Data.length){
                        //$("#pleasewait"+typeid).before(allhtmlword);
                        $("#typeid"+typeid+" .bodybox").append(allhtmlword);
                        $("iframe body").css("padding","0");
                        ajrunning="no";//加载完成
                        isclick=0;
                        //console.log("所有数据加载完成");
                    }
                }
                readyover=1;
                $("#newslistbody").scrollLeft(allavawidth);
            }
            //mySwipermain.enableTouchControl();
            stopswiper="";
            $("body").css("overflow","auto");
        }
    });
}
function aj2(nowpage,currentIndex,pageSize){
    addnewswiper();
    console.log("加载历史执行");
    ajrunning="yes";
    isclick=0;
    if(typeid==7){
        choicecity=$.cookie("choicecity7");
        if($.cookie("choicecityname7")){
            $("#choicecity").html($.cookie("choicecityname7"));//页面展示城市名
        }
    }else if(typeid==36){
        choicecity=$.cookie("choicecity36");
        if($.cookie("choicecityname36")){
            $("#choicecity").html($.cookie("choicecityname36"));//页面展示城市名
        }
    }else if(typeid==110){
        choicecity=$.cookie("choicecity110");
        if($.cookie("choicecityname110")){
            $("#choicecity").html($.cookie("choicecityname110"));//页面展示城市名
        }
    }
    var ajaxnum=0;//加载了几条数据
    $.ajax({
        type:"get",
        datatype:"json",
        url:"https://www.pulu.com/webapi/api/PuluNews/GetPageDataByTypeId1?typeId="+typeid+"&currentIndex="+currentIndex+"&pageSize="+pageSize+"&userId="+id+choicecity,
        success:function(data){
            //$("#typeid"+typeid+" .newsbox").remove();
            if(data.Data==""||!data.Data){
                //console.log("没有数据了");
                $("#pleasewait"+typeid+" .waiting").css("display","none");
                $("#pleasewait"+typeid+" .nonews").css("display","block");
                isclick=0;
            }else{
                //所有要添加的字符串
                var allhtmlword="";
                for(var i=0;i<data.Data.length;i++){
                    ajaxnum++;//加载了几条数据
                    //截取时间
                    var tim="";
                    if(data.Data[i].published_date){
                        tim=getDateDiff(getDateTimeStamp(data.Data[i].published_date));
                    };
                    if(data.Data[i].title.length>20){
                        data.Data[i].title=data.Data[i].title.substr(0,20)+"...";
                    };
                    if(data.Data[i].thumb){
                        var iframeimg=showImg(data.Data[i].thumb,data.Data[i].id,data.Data[i].title,data.Data[i].url);
                        allhtmlword+="<div class='newsbox'  id='"+data.Data[i].id+"'><div class='tpl-2' onclick='hrefto(this)' data-title='"+data.Data[i].title+"'data-pagenum='"+currentIndex+"' data-newsimg='"+data.Data[i].thumb+"' data-id='"+data.Data[i].id+"' data-url='"+data.Data[i].url+"'><a><div class='clr'><div class='info-content rt'><div class='text-content' ><h2><p>"+data.Data[i].title+"</p></h2></div><div class='news-from'><span class='src-net'>"+data.Data[i].sitename+"·"+tim+"</span><span class='sendit rt' onclick='shareit(this)' data-nid='"+data.Data[i].id+"'><img src='../img/newsshare2.png' data-nid='"+data.Data[i].id+"'></span><span class='src-delet rt overflow' onclick='deleteitfun(this)' data-url='"+data.Data[i].host+","+data.Data[i].sitename+"' id='new"+data.Data[i].id+"'><img src='../img/newsdel2.png'></span></div></div><div class='pic-content'>"+iframeimg+"</div></div></a></div></div>";
                    }else if(!data.Data[i].thumb){
                        allhtmlword+="<div class='newsbox' id='"+data.Data[i].id+"'><div class='tpl-3' data-id='"+data.Data[i].id+"' onclick='hrefto(this)' data-title='"+data.Data[i].title+"' data-url='"+data.Data[i].url+"' data-pagenum='"+currentIndex+"'><a><div class='text-content'><h2><p>"+data.Data[i].title+"</p></h2></div><div class='news-from'><span class='src-net'>"+data.Data[i].sitename+"·"+tim+"</span><span class='sendit rt' onclick='shareit(this)' data-nid='"+data.Data[i].id+"'><img src='../img/newsshare2.png' data-nid='"+data.Data[i].id+"'></span><span class='src-delet rt overflow' id='new"+data.Data[i].id+"' onclick='deleteitfun(this)' data-url='"+data.Data[i].host+","+data.Data[i].sitename+"'><img src='../img/newsdel2.png'></span></div></a></div></div>";
                    }
                    //console.log(ajaxnum);
                    if(ajaxnum===pageSize){
                        //$("#pleasewait"+typeid).before(allhtmlword);
                        $("#typeid"+typeid+" .bodybox").append(allhtmlword);
                        console.log($.cookie("totop"));
                        var t=parseFloat($.cookie("totop"));
                        console.log("完成滚动："+t);
                        $("#typeid"+typeid).scrollTop(t);
                        $.cookie("totop","");
                        alert("完成："+$.cookie("totop",""));
                        //document.body.scrollTop=t;
                        ajrunning="no";//加载完成
                    }
                };
                $.cookie("totop","");
                $("#newslistbody").scrollLeft(allavawidth);
            }
        }
    });
}
//跳转 历史定位 新闻详情页
function hrefto(d){
    $.cookie("currentIndex","");
    $.cookie("scrollTop","");
    $.cookie("newsid","");
    $.cookie("totop","");
    var urlinfo;
    //var nthisid;
    //
    if(d.nodeName==="IMG"||d.nodeName==="DIV"){
        urlinfo=d.dataset.url;
        //var nthisid=d.dataset.id;
    }
    if(urlinfo){
        if(d.dataset.newsimg){
            $.cookie("newsimg",d.dataset.newsimg);
        }else{
            $.cookie("newsimg","");
        }
        var t = $("#typeid"+typeid).scrollTop();

        $.cookie("newsid",d.dataset.id);
        $.cookie("totop",t);
        var currentIndex= parseFloat(d.dataset.pagenum);
        $.cookie("currentIndex",currentIndex);
        var scrollTop=$("#typeid"+typeid).scrollTop();
        $.cookie("scrollTop",scrollTop);
        $.cookie("newstitle",d.dataset.title);
        $.cookie("newsurl",urlinfo);
        $.cookie("newstypeid",typeid);
        location.href="http://www.pulu.com/weixin/newsdetail.html?newsid="+$.cookie("newsid")+"&fromuser="+id;
        //$.ajax({
        //    type:"post",
        //    datatype:"json",
        //    url:"https://www.pulu.com/webapi/api/PuluNews/AddCount",
        //    data:{"newsId": d.dataset.id},
        //    success:function(d){
        //        location.href="http://www.pulu.com/weixin/newsdetail.html?newsid="+$.cookie("newsid")+"&fromuser="+id;
        //    }
        //})
    }
}
//关闭新闻详情页
$("#iframegoback").click(function(){
    $("#newsiframe").attr("src","");
    $("#seenews").css("display","none");
    $("#page_wrapper").css("display","block");
    //$("body").css("overflow","auto");
    $(".wrapper.home_feed").css("overflow","auto");
});
//详情页面分享操作
$("#iframesharebtn").click(function(e){
    console.log(cansend);
    console.log(newstitle);
    var newsid= e.target.dataset.newsid;
    $("#sharetitleword div").html(newstitle[newsid]);
    $("#seenews").css("display","none");
    $("#shareword").css("display","block");
    //转发确定按钮
    if(cansend==1){
        console.log(cansend);
        sendcommentbtn.onclick=function(){
            cansend=0;
            sendcommentbtn.disabled=true;
            if(commentinput.value){
                if(commentinput.value.match(/^\s+$/g)){
                    $("#sharewaiting").css("display","block");
                    $.ajax({
                        type:"post",
                        datatype:"json",
                        url:addshareurl,
                        data:{"contentid":newsid,"userid":id,"fromuser":"","des":"","contenttype":1},
                        success:function(data){
                            console.log(data);
                            commentinput.value="";
                            shareword.style.display="none";
                            $("#sharewaiting").css("display","none");
                            $("#seenews").css("display","block");
                            $("#collectword").css("display","block");
                            setTimeout(function(){
                                $("#collectword").css("display","none");
                            },1000);
                            clearTimeout();
                            cansend=1;
                            sendcommentbtn.disabled=false;
                        }
                    })
                }else{
                    $.ajax({
                        type:"post",
                        datatype:"json",
                        url:addshareurl,
                        data:{"contentid":newsid,"userid":id,"fromuser":"","des":commentinput.value,"contenttype":1},
                        success:function(data){
                            console.log(data);
                            commentinput.value="";
                            shareword.style.display="none";
                            $("#seenews").css("display","block");
                            $("#collectword").css("display","block");
                            setTimeout(function(){
                                $("#collectword").css("display","none");
                            },1500);
                            clearTimeout();
                            cansend=1;
                            sendcommentbtn.disabled=false;
                        }
                    })
                }
            }else{
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:addshareurl,
                    data:{"contentid":newsid,"userid":id,"fromuser":"","des":"","contenttype":1},
                    success:function(data){
                        console.log(data);
                        commentinput.value="";
                        shareword.style.display="none";
                        $("#collectword").css("display","block");
                        $("#seenews").css("display","block");
                        setTimeout(function(){
                            $("#collectword").css("display","none");
                        },1500);
                        clearTimeout();
                        cansend=1;
                        sendcommentbtn.disabled=false;
                    }
                })
            }
        };
    }
    //取消
    cancelbtn.onclick=function(){
        commentinput.value="";
        $("#seenews").css("display","block");
        shareword.style.display="none";
    }
});
//判断屏蔽个数
function maxnum(){
    //newscount= d.Data.newsCount;//已经屏蔽的新闻个数
    //urlcount= d.Data.siteCount;//已经屏蔽的网址个数
    //keywordcount= d.Data.keyWordsCount;//已经屏蔽的关键词个数
    if(newscount>=100){
        $("#deleteit").html("屏蔽新闻已达上限");
    }else{
        $("#deleteit").html("屏蔽该新闻");
    };
    if(urlcount>=100){
        $("#deleteurl").html("屏蔽网站已达上限");
    }else{
        $("#deleteurl").html("屏蔽该网站");
    };
    if(keywordcount>=100){
        $("#inputkey").attr("placeholder","屏蔽关键词已达上限");
        $("#inputkey").attr({"disabled":"disabled"});
        $("#sendword").addClass("maxnum");
    }else{
        $("#inputkey").attr("placeholder","");
        $("#inputkey").removeAttr("disabled");
        $("#sendword").removeClass("maxnum");
    }
}
//屏蔽操作
var spanx;
var urlinfo;
function deleteitfun(spanx){
    //取消事件冒泡
    var e=arguments.callee.caller.arguments[0]||event; //若省略此句，下面的e改为event，IE运行可以，但是其他浏览器就不兼容
    if (e && e.stopPropagation) {
        // this code is for Mozilla and Opera
        e.stopPropagation();
    } else if (window.event) {
        // this code is for IE
        window.event.cancelBubble = true;
    }
    if(e.target.dataset.url||e.target.nodeName==="IMG"){
        if(e.target.nodeName==="IMG"){
            thisid=e.target.parentNode.id.match(/([0-9]+)/)[0];
            urlinfo=e.target.parentNode.dataset.url;
        }else{
            thisid=e.target.id.match(/([0-9]+)/)[0];
            urlinfo=e.target.dataset.url;
        }
        <!--模态框淡入淡出-->
        var overflowlist=document.getElementsByClassName("overflow");
        var modalbg=document.getElementsByClassName("modal_bg")[0];
        var modal=document.getElementsByClassName("action_menu_container")[0];
        var cancel=document.getElementsByClassName("cancel")[0];
        var timer;
        $(".modal_bg").css("display","block");
        $(".action_menu_container").css("display","block");
        $("#inputkey").val("");//清空输入框上次数据
        cancel.onclick=function(){
            if(modalbg.style.display=="block"&&modal.style.display=="block"){
                modalbg.className+=' animate_out';
                modal.className+=' animate_out';
            }
            timer=setTimeout(changeclass,100);
        };
        function changeclass(){
            modalbg.className='modal_bg';
            modal.className='action_menu_container';
            clearTimeout();
            timer=null;
            changedisplay();
        }
        function changedisplay(){
            modalbg.style.display="none";
            modal.style.display="none";
        }
        //屏蔽该新闻
        $("#deleteit").click(function(){
            console.log("ajrunning",ajrunning);
            console.log("isclick",isclick);
            if(isclick===0&&newscount<100){
                isclick=1;
                if(modalbg.style.display=="block"&&modal.style.display=="block"){
                    modalbg.className+=' animate_out';
                    modal.className+=' animate_out';
                }
                timer=setTimeout(changeclass,100);
                console.log("屏蔽该新闻内部id："+thisid);
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:"https://www.pulu.com/webapi/api/PuluShield/Addpulu_shield",
                    data:{"userId":id,"content":thisid,"shieldtype":3},
                    success:function(data){
                        console.log(data);
                        console.log(thisid);
                        if(ajrunning==="no"){//如果加载完成
                            $("div#"+thisid).remove();
                            isclick=0;
                            newscount++;
                            thisid=null;
                            var newsboxlen=document.getElementsByClassName("newsbox").length;
                            //页面剩余新闻小于等于5个
                            if(newsboxlen<=5){
                                isclick=0;
                                currentIndex++;
                                //aj(currentIndex,pageSize);
                                aj(nowpage,currentIndex,pageSize);
                            }
                        }
                    }
                })
            }

        });
        //屏蔽该网址
        $("#deleteurl").click(function(e){
            if(isclick===0&&urlcount<100){
                isclick=1;
                if(modalbg.style.display=="block"&&modal.style.display=="block"){
                    modalbg.className+=' animate_out';
                    modal.className+=' animate_out';
                }
                timer=setTimeout(changeclass,100);
                console.log("屏蔽网站内部id："+thisid);
                console.log(urlinfo);
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:"https://www.pulu.com/webapi/api/PuluShield/Addpulu_shield",
                    data:{"userId":id,"content":urlinfo,"shieldtype":2},
                    success:function(da){
                        urlinfo=null;
                        $.cookie("currentIndex","");
                        $.cookie("scrollTop","");
                        $.cookie("newsid","");
                        $.cookie("totop","");
                        currentIndex=1;
                        pageSize=10;
                        //$(".HomeMainFeed div").remove();
                        $("#typeid"+typeid+" .newsbox").remove();
                        //aj(currentIndex,pageSize);
                        aj(nowpage,currentIndex,pageSize);
                        //console.log(da);
                        //console.log(thisid);
                        //if(ajrunning==="no"){
                        //    $("div#"+thisid).remove();
                        //    isclick=0;
                        //    newscount++;
                        //    thisid=null;
                        //
                        //    var newsboxlen=document.getElementsByClassName("newsbox").length;
                        //    //页面剩余新闻小于等于5个
                        //    if(newsboxlen<=5){
                        //        isclick=0;
                        //        currentIndex++;
                        //        aj(currentIndex,pageSize);
                        //    }
                        //}
                    }
                })
            }
        });
        //屏蔽关键词
        $("#sendword").click(function(){

            if(isclick===0&&keywordcount<100){
                if($("#inputkey").val()&&$("#inputkey").val().length>0&&!$("#inputkey").val().match(/\s/)){
                    isclick=1;
                    $.ajax({
                        type:"post",
                        datatype:"json",
                        url:"https://www.pulu.com/webapi/api/PuluShield/Addpulu_shield",
                        data:{"userId":id,"content":$("#inputkey").val(),"shieldtype":1},
                        success:function(da){
                            console.log("屏蔽关键词");
                            console.log(da);
                            timer=setTimeout(changeclass,100);
                            isclick=0;
                            keywordcount++;
                        }
                    })
                }
            }

        });
    }
}
//分享
function shareit(e){
    //取消事件冒泡
    var e=arguments.callee.caller.arguments[0]||event; //若省略此句，下面的e改为event，IE运行可以，但是其他浏览器就不兼容
    if (e && e.stopPropagation) {
        // this code is for Mozilla and Opera
        e.stopPropagation();
    } else if (window.event) {
        // this code is for IE
        window.event.cancelBubble = true;
    }

    //if ( e && e.stopPropagation ) {
    //    e.stopPropagation();
    //} else {
    //    window.event.cancelBubble = true;
    //}
    //"转发操作");
    //console.log(cansend);
    $(".HeaderSwitcher.ReadSwitcher.SubHeader").css("display","block");
    //转发
    if(e.target.dataset.nid){
        $.cookie("sharenewsid",e.target.dataset.nid);
        location.href="sendsharepage.html?type=1";
    }
}
//新改写转发
var cansend=1;// 1可以转发 0不可以转发

//控制屏蔽关键词按钮样式变化
$(function(){
    $("#sendword").bind('input propertychange', function() {
        //$("#sendword").css("init");
        $('#sendword').attr('class','init');
        document.getElementById("sendword").className="init";
    });
});